﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Wsp365.Anonymous
{
    public static class WebHelper
    {
        public static SPList GetListByWebRelativeUrl(this SPWeb web, string listUrl)
        {

            return web.GetList(web.SafeServerRelativeUrl() + listUrl);
        }

        /// <summary>
        /// Get the serverrelative url with an ending /
        /// </summary>
        /// <param name="web"></param>
        /// <returns>ServerRelativeUrl with ending /</returns>
        public static string SafeServerRelativeUrl(this SPWeb web)
        {
            string webUrl = web.ServerRelativeUrl;
            if (webUrl != "/")
            {
                webUrl = webUrl + "/";
            }
            return webUrl;
        }
    }
}
